from rest_framework.generics import ListAPIView,CreateAPIView
from meiduo_admin.my_paginate import MyPageNumberPagination
from . import user_serializers
from users.models import User

#7,获取用户列表
class UserListView(ListAPIView,CreateAPIView):
    pagination_class = MyPageNumberPagination
    serializer_class = user_serializers.UserListSerializer
    # queryset = User.objects.all()

    def get_queryset(self):
        #1,获取关键字
        keyword = self.request.query_params.get("keyword")

        #2,返回数据源
        if keyword:
            return User.objects.filter(username__contains=keyword).all()
        else:
            return User.objects.all()
